﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "UIComponent.h"

namespace gcmp
{
    class UniIdentity;
    class IParameterDefinition;
    class IDocument;
}

namespace Sample
{
    class IParameterDisplay;

    /// \brief 参数显示管理类（文档级别）
    class UICOMPONENT_EXPORT IParameterDisplayManager
    {
        DEFINE_CAST_BASE(IParameterDisplayManager)
    public:
        /// \brief 析构函数
        ~IParameterDisplayManager();

        static IParameterDisplayManager* Get(const gcmp::IDocument* pDoc);

        /// \brief 回调函数，创建参数显示对象
        ///
        /// \param pParameterDefinition  当前参数定义
        /// \param pDoc  当前文档
        typedef std::function<gcmp::OwnerPtr<IParameterDisplay>(const gcmp::IDocument* pDoc, const gcmp::IParameterDefinition* pParameterDefinition)> IParameterDisplayCreator;
        
        /// \brief 设置回调函数
        ///
        /// \param creator 创建参数显示对象的回调函数
        static void SetParameterDisplayCreator(IParameterDisplayCreator creator);

        /// \brief 获取回调函数
        ///
        /// \param creator 获取参数显示对象的回调函数
        static IParameterDisplayCreator GetParameterDisplayCreator();

        /// \brief 返回参数显示对象
        ///
        /// \param uid 参数跨文档唯一的标识符
        /// \return 参数显示对象
        virtual IParameterDisplay* GetParameterDisplay(const gcmp::UniIdentity& uid) = 0;

        /// \brief 返回参数显示对象
        ///
        /// \param pParamDef 参数定义
        /// \return 参数显示对象
        virtual IParameterDisplay* GetParameterDisplay(const gcmp::IParameterDefinition* pParamDef) = 0;

        /// \brief 删除参数显示对象
        ///
        /// \param uid 参数跨文档唯一的标识符
        /// \return 返回true表示删除成功，返回false表示删除失败
        virtual bool DeleteParameterDisplay(const gcmp::UniIdentity& uid) = 0;

        /// \brief 添加自定义参数类型的参数显示对象
        ///
        /// 只允许ParameterDisplayType为Custom类参数显示方式
        /// \param oParameterDisplay 参数显示对象
        /// \return 返回true表示添加成功，否则表示失败
        /// \see ParameterDisplayType
        virtual bool AddCustomParameterDisplay(gcmp::OwnerPtr<IParameterDisplay> oParameterDisplay) = 0;

    public:
        /// \brief 添加内建参数类型的参数显示对象
        ///
        /// 只允许ParameterDisplayType为BuiltIn类参数显示方式
        /// \param oParameterDisplay 参数显示对象
        /// \return 返回true表示添加成功，否则表示失败
        /// \see ParameterDisplayType
        static bool AddBuiltInParameterDisplay(gcmp::OwnerPtr<IParameterDisplay> oParameterDisplay);

        /// \brief 替换内建参数类型的参数显示对象
        ///
        /// 只允许ParameterDisplayType为BuiltIn类参数显示方式
        /// \param oParameterDisplay 参数显示对象
        /// \return 返回true表示替换成功，否则表示失败
        /// \see ParameterDisplayType
        static bool ReplaceBuiltInParameterDisplay(gcmp::OwnerPtr<IParameterDisplay> oParameterDisplay);
    };
}

